<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body{
            background-image: url("../../images/bg1.jpg");
            background-repeat: no-repeat;
            background-size: 2000px;
        }

        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">旧的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="old_password" lay-verify="required" lay-reqtext="旧的密码不能为空" placeholder="请输入旧的密码"  value="" class="layui-input" id="old_password">
                    <tip>填写自己账号的旧的密码。</tip>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="new_password" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码"  value="" class="layui-input" id="new_password">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">新的密码</label>
                <div class="layui-input-block">
                    <input type="password" name="again_password" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码"  value="" class="layui-input" id="again_password">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" id="change" onclick="change()">确认修改</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../../js/jquery3.6.0.js"></script>
<script>
    function change(){
        //获取本地存储的数据
        let tuser=JSON.parse(localStorage.getItem("key"));
        //获取当前用户的id数组
        let tId=JSON.parse(localStorage.getItem("tId"));
        //获取用户输入的旧密码
        let oldPsw=$("#old_password").val();
        //获取用户输入的两次新密码
        let newPsw=$("#new_password").val();
        let againPsw=$("#again_password").val();
        //循环数据
        one:
        for(let i=0;i<tuser.length;i++){
        two:
            for(let j=0;j<tId.length;j++){
                let loginId=tId[0].id;
                // console.log(loginId);  //拿到当前员工的id
                if(loginId==tuser[i].id){
                    if(oldPsw==tuser[i].password){
                        if(newPsw==againPsw){
                            tuser[i].password=newPsw;
                            alert("修改成功！");
                        }else{
                            alert("两次密码输入不一致，请重新输入！");
                            break;
                        }
                    }else{
                        alert("原始密码错误，请重新输入！");
                        break;
                    }
                    break one;
                }
            }
        }
        //将最新的数据保存在本地
        localStorage.setItem("key",JSON.stringify(tuser));
        $("input").val("");
    }
</script>
</body>
</html>